<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="layout :: common_header(~{::title})">
    <title th:text="${shop.name+'-订单管理-订单总览-华衣聚石塔'}"></title>
</head>
<body th:replace="layout :: common_body(~{::div.layui-body})">

<div class="layui-body" style="padding:15px;">
    <style type="text/css">
        .update {
            display: inline-block;
            margin-left: 15px;
            padding: 0 20px;
            height: 40px;
            line-height: 40px;
            font-size: 14px;
            background: #009789;
            color: #fff;
            text-align: center;
            border-radius: 3px;
            cursor: pointer;
        }

        .update i {
            display: inline-block;
            margin-right: 10px;
            vertical-align: middle;
            width: 30px;
            height: 30px;
            background: url();
        }
        .T-box {
            width: 400px;
            padding: 0 20px;
            text-align: left;
        }

        .T-box p {
            position: relative;
            height: 36px;
            line-height: 36px;
            font-size: 14px;
            margin-bottom: 15px;
        }

        .T-box p span {
            display: inline-block;
            padding-right: 15px;
            text-align: right;
            width: 110px;
            line-height: 36px;
            font-size: 14px;
        }

        .T-box p input, .T-box p select {
            width: 250px;
            padding: 0 5px;
            height: 34px;
            line-height: 34px;
            font-size: 14px;
            border: 1px solid #d3d3d3;
            outline: none;
        }

        .T-box p i {
            padding: 0 10px;
            line-height: 36px;
            font-style: normal;
        }

        .T-box p b {
            display: inline-block;
            margin-left: 10px;
            cursor: pointer;
            width: 60px;
            height: 36px;
            line-height: 36px;
            background: #c33;
            color: #fff;
            text-align: center;
            font-size: 13px;
            font-weight: normal;
        }
    </style>
    <div class="layui-tab layui-tab-brief" lay-filter="demo">
        <ul class="layui-tab-title" id="status_menu">
            <li><a th:href="@{/kwai/order_list(shopId=${shopId},status=30)}">待发货订单</a></li>
            <li><a th:href="@{/kwai/order_list(shopId=${shopId})}">全部订单</a></li>
        </ul>
    </div>

    <!-- content starts -->
    <blockquote class="layui-elem-quote">订单总览</blockquote>

    <fieldset class="layui-elem-field">
        <legend>按条件搜索</legend>
        <div class="layui-field-box">
            <form class="layui-form layui-form-pane1" method="get" action="/kwai/order_list">
                <input type="hidden" name="shopId" th:value="${shop.id}"/>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <input type="text" name="orderNum" th:value="${orderNum}" placeholder="订单编号" class="layui-input">
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">下单时间</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="startTime" th:value="${startTime}" id="startTime" autocomplete="off"
                                   style="width: 120px;" placeholder="yyyy-MM-dd">
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="endTime" th:value="${endTime}" id="endTime" style="width: 120px;" autocomplete="off" placeholder="yyyy-MM-dd">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <select name="status" id="status">
                                <option value="">订单状态</option>
                                <option th:each="item:${T(com.b2c.entity.enums.third.EnumKwaiOrderStatus).values()}" th:value="${item.getIndex()}" th:text="${item.getName()}">等待发货</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button type="submit" class="layui-btn">搜索</button>
                        <i>总共：<span style="color: red" th:text="${totalSize}"></span>条记录</i>
                    </div>
                    <div class="layui-inline">
                        <span id="upd_order" class="layui-btn layui-btn-normal">更新订单</span>
                        <span id="upd_order_" style="display: none;" class="update"><i></i>更新中</span>



                    </div>
                </div>

            </form>
        </div>
    </fieldset>

    <!-- start dd-wrapper -->
    <link rel="stylesheet" href="/goods/order.css"/>
    <div class="dd-wrapper">
        <table class="dd-table">
            <tr>
                <th width="20%">商品</th>
                <th>订单金额</th>
                <th width="20%">订单信息</th>
                <th>物流信息</th>
                <th>订单状态</th>
                <th>操作</th>
            </tr>
            <tr th:each="item:${lists}">
                <td>
                    <div th:each="it:${item.getItems()}">
                        <img th:src="${it.getItempicurl()}">
                        <p>
                            <span th:text="${#strings.abbreviate(it.getItemtitle(),18)}"></span><br/>
                            规格：[[${it.goodsspec}]]<br/>
                            单价: ¥[[${it.price}]] 数量：X[[${it.num}]]
                        </p>
                    </div>
                </td>
                <td><b>¥<span th:text="${item.expressfee + item.totalfee}"></span></b><br>（含运费：¥[[${item.expressfee}]]）</td>
                <td>
                    <div>
                        <p>订单编号：[[${item.oid}]]</p>
                        <p th:text="${'下单时间：'+#dates.format(item.getCreatetime()*1000, 'yyyy-MM-dd HH:mm:ss')}"></p>
                        <p style="color: red">收货人：[[${item.consignee}]]&nbsp;[[${item.mobile}]]&nbsp;[[${item.address}]]</p>
                        <p>买家备注:<b th:text="${item.getBuyerRemark()}"></b></p>
                        <p>卖家备注:<b th:text="${item.getSellerRemark()}"></b></p>
                    </div>
                </td>
                <td>
                    <div th:if="${item.getLogisticsCode() !=null }">
                        <p>物流公司：[[${item.logisticsCompany}]]</p>
                        <p>物流单号：[[${item.logisticsCode}]]</p>
                    </div>
                </td>
                <td>
                    <p th:text="${T(com.b2c.entity.enums.third.EnumKwaiOrderStatus).getName(item.getStatus())}"></p>
                    <p th:text="'仓库订单状态：'+ ${T(com.b2c.entity.enums.erp.EnumErpOrderSendStatus).getName(item.getSendStatus())}"></p>
                </td>
                <td>
                    <a th:href="@{/kwai/orderDetail(id=${item.getId()},shopId=${shopId})}">查看详情</a>
                    <a th:if="${item.getAuditStatus()==0 && item.getStatus() ==30}" th:href="@{/kwai/orderDetail(id=${item.getId()},shopId=${shopId})}">订单确认</a>
                    <a th:if="${item.getAuditStatus() == 1 && not #strings.isEmpty(item.getLogisticsCode())}" th:attr="order-id=${item.getOid()},code=${item.getLogisticsCode()},name=${item.getLogisticsCompany()}" class="order_send" >订单发货</a>
                </td>
            </tr>
        </table>
    </div>
    <!-- end dd-wrapper -->
    <div class="layui-box layui-laypage layui-laypage-default pageBox">
        <paging:pager th:value="${pageIndex}" th:rows="${totalSize}" th:size="${pageSize}"/>
    </div>

    <script type="text/template" id="modify_address">
        <div class="T-box">
            <p><span>姓名</span><input type="text" id="userName"/></p>
            <p><span>手机号</span><input type="text" id="mobile"/></p>
            <p><span>收货地址</span><input type="text" id="address"/></p>
        </div>
    </script>
    <script type="text/javascript" src="/goods/Tips/Tips.min.js"></script>
    <script type="text/javascript">
        var layer;
        var $;
        var windowOpen;
        layui.use(['laydate', 'jquery', 'form', 'layer'], function () {
            var laydate = layui.laydate;
            $ = layui.jquery;
            var form = layui.form;
            layer = layui.layer;
            laydate.render({
                elem: '#startTime'
                ,max: 0
            });
            laydate.render({
                elem: '#endTime'
                ,max: 0
            });

            $(function () {
                $("#status").val([[${status}]]);
                form.render('select'); //刷新select选择框渲染

                if($("#status").val()==1){
                    $("#status_menu li:nth-child(1)").addClass("layui-this");
                    $("#status_menu li:nth-child(2)").removeClass("layui-this");
                }else{
                    $("#status_menu li:nth-child(2)").addClass("layui-this");
                    $("#status_menu li:nth-child(1)").removeClass("layui-this");
                }

                //更新订单
                $("#upd_order").click(function () {
                    $("#upd_order").hide();
                    $("#upd_order_").show();
                    var startTime = $("#startTime").val();
                    var endTime = $("#endTime").val();
                    var data = {
                        startTime:startTime,
                        endTime:endTime,
                        updType:0
                    };
                    $.ajax({
                        url: "/ajax_kwai/pull_order",
                        type: "POST",
                        dataType: "JSON",
                        contentType: 'application/json',
                        data:JSON.stringify(data),
                        success: function (res) {
                            if (res.code == 0) {
                                location.href = "/kwai/order_list?shopId=13";
                            }else if(res.code==601){
                                location.href = "/kwaixiaodian/oauth";
                            }else {
                                Tips.alert(res.msg);
                            }
                            $("#upd_order").show();
                            $("#upd_order_").hide();
                        }
                    })
                });
                //订单发货
                $(".order_send").click(function () {
                    var $this = $(this);
                    var dataObj = {orderId: $this.attr("order-id"),code:$this.attr("code"),name:$this.attr("name")}
                    $.ajax({
                        url: "/ajax_kwai/send_order",
                        type: "POST",
                        dataType: "JSON",
                        contentType: 'application/json',
                        data: JSON.stringify(dataObj),
                        success: function (res) {
                            if (res.code == 0) {
                                alert("发货成功");
                                location.reload();
                            }else if(res.code==601){
                                location.href = "/kwaixiaodian/oauth";
                            }else {
                                alert(res.msg);
                            }
                        }
                    })
                });
            })
        });

    </script>

    <!-- 模板  -->
    <script type="text/template" id="tpl-group">
        <div class="T-box" style="width: 1000px">
            <div class="dd-log">
                <ul id="sendContext">
                </ul>
            </div>
        </div>
    </script>


</div>
</body>
<html>
